package com.cortex.papaya.adapter;

import java.util.List;

import com.cortex.papaya.search.Category;
import com.cortex.papaya.view.CategoryView;
import com.cortex.papayasearch.R;

import android.content.ClipData;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.DragShadowBuilder;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AbsListView;
import android.widget.BaseAdapter;

public class CategoryAdapter extends BaseAdapter {

	private List<Category> categories;
	private Context context;

	public CategoryAdapter(Context context,List<Category> categories){
		this.context = context;
		this.categories = categories;
	}
	
	@Override
	public int getCount() {
		return categories.size();
	}

	@Override
	public Object getItem(int position) {
		return categories.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Category category = categories.get(position);
		CategoryView categoryView = null;
		if(convertView == null){
			LayoutInflater inflter = LayoutInflater.from(context);
			categoryView = (CategoryView)inflter.inflate(R.layout.view_category, null);
			categoryView.setCategory(category);
			int width = AbsListView.LayoutParams.MATCH_PARENT;
			int height = (int) context.getResources().getDimension(R.dimen.category_height);
			categoryView.setLayoutParams(new AbsListView.LayoutParams(width,height));
			convertView = categoryView;
		}
		((CategoryView)convertView).setCategory(category);
		return convertView;
	}
}

